#ifndef __mml_polygon_h__
#define __mml_polygon_h__

#include <math.h>
#include <float.h>

#include <mml/api.h>

namespace mml
{
  /** Centroid, normal and area of polygon which may be concave. */
  MMLAPI void analysePolygon(int n,
                             double const* vertexData,
                             double normal[3],
                             double centroid[3],
                             double& area,
                             double& projectedArea);

  /** Remove least-significant vertices from a polygon. */
  MMLAPI int simplifyPolygon(int n,
                             double* vertexData,
                             double const& reltol = 1.0e-3);

  /** Create polygon from unsorted vertex list. */
  MMLAPI void createPolygon(int n, double* vertexData);

  /** Add vertices to polygon so that the maximum vertex distance is smaller
      than factor times circumference. */
  MMLAPI int augmentPolygon(int n, double* vertexData, double const& factor = 0.1);

  /** Reduce a polygon to part 'above' plane. */
  MMLAPI int reducePolygon(int n,
                           double* vertexData,
                           double const planeNormal[3],
                           double const& planeDistance);

  /** Flatten a polygon and also compute normal, centroid and area. */
  MMLAPI void flattenPolygon(int n,
                             double* vertexData,
                             double normal[3],
                             double centroid[3],
                             double& area,
                             double& projectedArea);
}

#endif  // __mml_polygon_h__
